package com.goktech.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName javaUtil
 * @Description TODO
 * @Author 邱华英
 * @Date 2022/9/26 19:46
 * @Version 1.0
 */

public class javaUtil {
    public static Map splitList(String symbal, List byAll, int yeshu, List books){
        if("add".equals(symbal)){
            if(byAll.size() > (yeshu*5)){
                yeshu++;
                int last = byAll.size() < yeshu*5 ? byAll.size() : yeshu*5;
                books = byAll.subList((yeshu-1) * 5,last);
                System.out.println("yeshu*5:"+yeshu*5+",last:"+last);

            }else{
                int last = byAll.size() < yeshu*5 ? byAll.size() : yeshu*5;
                books = byAll.subList((yeshu - 1) * 5,last);
                System.out.println("addlast:"+last+",yeshu:"+yeshu);
            }
        }else if("delete".equals(symbal)){
            System.out.println("yeshu:"+yeshu);
            if(yeshu-1 >= 1){
                yeshu--;
                books = byAll.subList((yeshu-1)* 5, yeshu* 5);
            }else{
                int last = byAll.size() < yeshu*5 ? byAll.size() : yeshu*5;
                System.out.println("last:"+last);
                books = byAll.subList((yeshu - 1) * 5,last);
            }
            System.out.println("deleteUsers:"+books);
        }else{
            int last = byAll.size() < yeshu*5 ? byAll.size() : yeshu*5;
            books = byAll.subList((yeshu - 1) * 5, last);
        }

        Map<String,Object> maps = new HashMap<>();
        maps.put("books",books);
        maps.put("yeshu",yeshu);
        return maps;
    }

    public static final String KEY_MD5 = "MD5";

    public static  String  getResult(String inputStr)
    {
        BigInteger bigInteger=null;

        try {
            MessageDigest md = MessageDigest.getInstance(KEY_MD5);
            byte[] inputData = inputStr.getBytes();
            md.update(inputData);
            bigInteger = new BigInteger(md.digest());
        } catch (Exception e) {e.printStackTrace();}
        return bigInteger.toString(16);
    }

    public static byte[] encryMD5(byte[] data) throws NoSuchAlgorithmException {
        MessageDigest mds = MessageDigest.getInstance(KEY_MD5);
        mds.update(data);
        return mds.digest();
    }
}
